import os
from Utilities.AutoGetOperator.selectionMethod.selectPackage import get_func


root_path = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))  # 项目的根目录
project_path = os.path.join(root_path, 'Operators')  # 项目所在目录
file_a_path = os.path.join(project_path, 'SchweizerSklar.py')  # 目标文件目录
Operator_IVQ_ROFS=get_func(file_a_path,'SchweizerSklar')

# Operator_IVQ_ROFS=get_func(r'C:\Users\26510\pythonWorkplace\hh\DecisionSystem\Operators\OperationOperators\OperatorIVQROF.py',
#                            'Operator_IVQ_ROFS')
class BonferroniMeanA(Operator_IVQ_ROFS):


    def getResult(self):
        '''

        Returns:

        '''
        n = len(self.data_list)
        # ([0.7759791546084002, 0.8787196534747774], [0.20115050738736887, 0.3062587580645581])
        u1 = self.pow(self.data_list[0], self.a, self.q)
        u2 = self.pow(self.data_list[1], self.b, self.q)
        s1 = self.multi(u2, u1, self.q)
        s = s1
        for j in range(2,n):
            u1 = self.pow(self.data_list[0], self.a, self.q)
            u2 = self.pow(self.data_list[j], self.b, self.q)
            s1 = self.multi(u2, u1, self.q)
            s = self.add(s, s1, self.q)

        for i in range(n):
            if i==0:
                continue
            for j in range(n):
                if i != j:
                    u1 = self.pow(self.data_list[i], self.a, self.q)
                    u2 = self.pow(self.data_list[j], self.b, self.q)
                    s1 = self.multi(u2, u1, self.q)
                    s = self.add(s, s1, self.q)
        s = self.kmulti(s, 1 / (n * (n - 1)), self.q)
        s = self.pow(s, 1/(self.a + self.b), self.q)
        return s

class BonferroniMeanGA(Operator_IVQ_ROFS):

    def getResult(self):
        '''

        Returns:

        '''
        # 获得初始值
        n = len(self.data_list)
        # ([0.7759791546084002, 0.8787196534747774], [0.20115050738736887, 0.3062587580645581])
        u1 = self.kmulti(self.data_list[0], self.a, self.q)
        u2 = self.kmulti(self.data_list[1], self.b, self.q)
        s1 = self.add(u2, u1, self.q)
        s = s1
        for j in range(2, n):
            u1 = self.kmulti(self.data_list[0], self.a, self.q)
            u2 = self.kmulti(self.data_list[j], self.b, self.q)
            s1 = self.add(u2, u1, self.q)
            s = self.multi(s, s1, self.q)

        for i in range(n):
            if i==0:
                continue
            for j in range(n):
                if i != j:
                    u1 = self.kmulti(self.data_list[i], self.a, self.q)
                    u2 = self.kmulti(self.data_list[j], self.b, self.q)
                    s1 = self.add(u2, u1, self.q)
                    s = self.multi(s, s1, self.q)
        s = self.pow(s, 1 / (n * (n - 1)), self.q)
        s = self.kmulti(s, 1/(self.a + self.b), self.q)
        return s

class SchweizerSklarBonferroniMeanWA(Operator_IVQ_ROFS):


    def getResult(self):
        '''

        Returns:

        '''
        n = len(self.data_list)
        u1_temp = self.kmulti(self.data_list[0], self.weight_list[0], self.q)
        u1 = self.pow(u1_temp, self.a, self.q)
        u2_temp = self.kmulti(self.data_list[1], self.weight_list[1], self.q)
        u2 = self.pow(u2_temp, self.b, self.q)
        s1 = self.multi(u2, u1, self.q)
        s = s1
        for j in range(2, n):
            u1_temp = self.kmulti(self.data_list[0], self.weight_list[0], self.q)
            u1 = self.pow(u1_temp, self.a, self.q)
            u2_temp = self.kmulti(self.data_list[j], self.weight_list[j], self.q)
            u2 = self.pow(u2_temp, self.b, self.q)
            s1 = self.multi(u2, u1, self.q)
            s = self.add(s, s1, self.q)
        for i in range(n):
            if i==0:
                continue
            for j in range(n):
                if i != j:
                    u1_temp = self.kmulti(self.data_list[i], self.weight_list[i], self.q)
                    u1 = self.pow(u1_temp, self.a, self.q)
                    u2_temp = self.kmulti(self.data_list[j], self.weight_list[j], self.q)
                    u2 = self.pow(u2_temp, self.b, self.q)
                    s1 = self.multi(u2, u1, self.q)
                    s = self.add(s, s1, self.q)
        s = self.kmulti(s, 1 / (n * (n - 1)), self.q)
        s = self.pow(s,1/(self.a + self.b), self.q)
        return s

class BonferroniMeanWGA(Operator_IVQ_ROFS):


    def getResult(self):
        '''

        Returns:

        '''
        n = len(self.data_list)
        u1_temp = self.pow(self.data_list[0], self.weight_list[0], self.q)
        u1 = self.kmulti(u1_temp, self.a, self.q)
        u2_temp = self.pow(self.data_list[1], self.weight_list[1], self.q)
        u2 = self.kmulti(u2_temp, self.b, self.q)
        s1 = self.add(u2, u1, self.q)
        s = s1
        for j in range(2, n):
            u1 = self.kmulti(self.data_list[0], self.a, self.q)
            u2 = self.kmulti(self.data_list[j], self.b, self.q)
            s1 = self.add(u2, u1, self.q)
            s = self.multi(s, s1, self.q)

        for i in range(n):
            if i==0:
                continue
            for j in range(n):
                if i != j:
                    u1_temp = self.pow(self.data_list[i], self.weight_list[i], self.q)
                    u1 = self.kmulti(u1_temp, self.a, self.q)
                    u2_temp = self.pow(self.data_list[j], self.weight_list[j], self.q)
                    u2 = self.kmulti(u2_temp, self.b, self.q)
                    s1 = self.add(u2, u1, self.q)
                    s = self.multi(s, s1, self.q)
        s = self.pow(s, 1 / (n * (n - 1)), self.q)
        s = self.kmulti(s,1/(self.a + self.b), self.q)
        return s

class BonferroniMeanOWA(Operator_IVQ_ROFS):


    def getResult(self):
        '''

        Returns:

        '''
        # 将 数据集备份，将类中数据集属性 替换为 排序后的数据集
        data_list = self.data_list
        self.data_list = self.sortdata()


        n = len(self.data_list)
        u1_temp = self.kmulti(self.data_list[0], self.weight_list[0], self.q)
        u1 = self.pow(u1_temp, self.a, self.q)
        u2_temp = self.kmulti(self.data_list[1], self.weight_list[1], self.q)
        u2 = self.pow(u2_temp, self.b, self.q)
        s1 = self.multi(u2, u1, self.q)
        s = s1
        for j in range(2, n):
            u1_temp = self.kmulti(self.data_list[0], self.weight_list[0], self.q)
            u1 = self.pow(u1_temp, self.a, self.q)
            u2_temp = self.kmulti(self.data_list[j], self.weight_list[j], self.q)
            u2 = self.pow(u2_temp, self.b, self.q)
            s1 = self.multi(u2, u1, self.q)
            s = self.add(s, s1, self.q)
        for i in range(n):
            if i==0:
                continue
            for j in range(n):
                if i != j:
                    u1_temp = self.kmulti(self.data_list[i], self.weight_list[i], self.q)
                    u1 = self.pow(u1_temp, self.a, self.q)
                    u2_temp = self.kmulti(self.data_list[j], self.weight_list[j], self.q)
                    u2 = self.pow(u2_temp, self.b, self.q)
                    s1 = self.multi(u2, u1, self.q)
                    s = self.add(s, s1, self.q)
        s = self.kmulti(s, 1 / (n * (n - 1)), self.q)
        s = self.pow(s,1/(self.a + self.b), self.q)

        # 还原数据集
        self.data_list = data_list
        return s



if __name__ == "__main__":
    data= [([0.85, 0.95], [0.1, 0.2]), ([0.8, 0.9], [0.1, 0.2]), ([0.85, 0.95], [0.1, 0.2]), ([0.7, 0.8], [0.2, 0.3]),
        ([0.4, 0.5], [0.5, 0.6])]
    weight_list = [0.1, 0.2, 0.3, 0.1, 0.3]
    gbm = SchweizerSklarBonferroniMeanWA(data,weight_list)
    print(gbm.getResult())
